<?php
namespace Api\Controller;
class CategoryController extends BaseController {
    /**
     * 获取所有的分类数据
     */
    public function getAllCategories() {
        $m_category = M('category');
        $categories_parent = $m_category->field('cid,cname,cimg,cparent_id')->where(array(
            'cparent_id' => 0
        ))->select();
        foreach ($categories_parent as $key => $value) {
            $categories_child = $m_category->field('cid,cname,cimg,cparent_id')->where(array(
                'cparent_id' => $value['cid']
            ))->select();
            $value['children'] = $categories_child;
            $categories_parent[$key] = $value;
        }
        succeed($categories_parent);
    }
}